﻿<!DOCTYPE>
<html ng-app="testLogin">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, width=device-width, minimal-ui">
    <link rel="stylesheet" type="text/css" href="/css/style.css"/>
	<link rel="stylesheet" type="text/css" href="/css/pensonel.css" />
    <link rel="stylesheet" type="text/css" href="/framework/angular-tooltips-master/dist/angular-tooltips.min.css"/>
    <script type="text/javascript" src="/framework/angular.min.js"></script>
    <script src="/images/icon/iconfont.js" type="text/javascript"></script>
    <title ng-bind="systemTitle"></title>
</head>
<body  ng-controller="testLoginCtl">
	 
     <!--loading-->
        <div class="jisuloading" style="z-index:10001">
        <div class="img">
            <center>
            <img src="/images/yemianloding.gif" width="90" height="90" />
            </center>
            <div ng-if="!errmsg" ><span ng-bind="user_name"></span>正在登入系统请稍后。。。</div>
			<span ng-if="errmsg">登录状态已失效，请重新登录！<a href="javascript;;" onclick="location.href='/login.html'">重新登录</a></span>
        </div>
    </div>
<script src="/framework/angular-wang-editor/dist/js/lib/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="/framework/lodash.min.js"></script>
    <script type="text/javascript" src="/framework/restangular/restangular.min.js"></script>
    <script type="text/javascript" src="/framework/angular-toastr/angular-toastr.min.js"></script>
    <script type="text/javascript" src="/framework/angular-toastr/angular-toastr.tpls.min.js"></script>
    <script type="text/javascript" src="/system/service/common.js"></script>
	<script type="text/javascript" src="/system/service/personnelpathservice.js"></script>    
    <script type="text/javascript">
        var mainApp = angular.module("testLogin", ['Common', 'personnelmanagementS']).config(['toastrConfig', '$locationProvider', function (toastrConfig, $locationProvider) { $locationProvider.html5Mode({ enabled: true, requireBase: false }); } ]).controller('testLoginCtl', ['$scope', '$location', 'RequestUserService', 'RequestPopService', 'sysUserInfo', 'Msg', 'Restangular', function ($scope, $location, RM, RPS, sysUserInfo, Msg, Restangular) {
            Restangular.addFullRequestInterceptor(function(element, operation, route, url, headers, params, httpConfig) {     
                    return {              
                        headers: {"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"}  
                    };
                });
            var param = decodeURI($location.hash(), "UTF-8");
            var url = "";
            if (param.indexOf("/") != -1) {
                $scope.user_ID = param.split("/")[0];
                $scope.token = param.split("/")[1];
                sysUserInfo.setuserinfotoken($scope.token);
                if (param.split("/")[2] != undefined && param.split("/")[2].length > 0) {
                    var a = param.split("/");
                    a.splice(0, 2);
                    url = a.join("/");
                }
            } else {
                $scope.user_ID = param;
            }
            $scope.errmsg = false;
            var browser = {
                versions: function () {
                    var u = navigator.userAgent, app = navigator.appVersion;
                    return {         //移动终端浏览器版本信息
                        trident: u.indexOf('Trident') > -1, //IE内核
                        presto: u.indexOf('Presto') > -1, //opera内核
                        webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                        gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
                        mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
                        ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                        android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
                        iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
                        iPad: u.indexOf('iPad') > -1, //是否iPad
                        wp: u.indexOf('IEMobile') > -1, //是否wp
                        symbianos: !!u.match(/SymbianOS.*/), //是否SymbianOS
                        webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
                    };
                } (),
                language: (navigator.browserLanguage || navigator.language).toLowerCase()
            }

            //登录            
            $scope.user_login = function () {
                localStorage.setItem("flag", "");
                Restangular.addFullRequestInterceptor(function (element, operation, route, url, headers, params, httpConfig) {
                    //这个地方需要把登录得到的token写入到请求数据的头文件中
                    var usertoken = sysUserInfo.getuserinfotoken().toString();
                    if (usertoken == undefined || usertoken == null || usertoken == "") {
                        $scope.errmsg = true;
                        return;
                        //location.href="/login.html";
                    }
                    return {
                        headers: { "X-Session-Token": usertoken, "Content-Type": "application/x-www-form-urlencoded;charset=utf-8" }
                    };
                });
                RPS.personnelGetKey({ user_ID: $scope.user_ID }).then(function (retobj) {
                    if (retobj.errorcode == 0) {
                        if (retobj.data.state == 6) {
                            Msg.warning("注册审核未通过，请联系管理员！");
                        } else {
                            retobj.data.userId = retobj.data.user_ID;
                            retobj.data.username = retobj.data.user_Name;
                            if (retobj.data.user_Img == "" || retobj.data.user_Img == null || retobj.data.user_Img == undefined) {
                                retobj.data.user_Img = "/images/avatar.png";
                            }
                            localStorage.setItem("userinfo", JSON.stringify(retobj.data));

                            if (url.length > 0) {
                                window.location.href = url;
                            } else {

                                if (browser.versions.mobile || browser.versions.ios || browser.versions.android || browser.versions.symbianos || browser.versions.wp) {
                                    window.location.href = "/vue/index.html?H5ID="+retobj.data.organization_ID;
                                } else {
                                    if (retobj.data.powerLV == 99) {
                                        window.location.href = "/member/index.html";
                                    } else {
                                        window.location.href = "/system/index.html";
                                    }
                                }
                            }
                        }
                    } else if (retobj.errorcode == "43") {
                        Msg.warning("企业套餐已过期！");
                    } else if (retobj.errorcode == "44") {
                        Msg.warning("此账号已离职/结业，无法登录！");
                    } else if (retobj.errorcode == "35" || retobj.errorcode == "36") {
                        $scope.errmsg = true;
                    }
                });
            }
            $scope.user_login();
        } ]);
    </script>    
    <script type="text/javascript" src="/system/service/userpathservice.js"></script>
</body>
</html>
